<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="考试id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="examId">
              <a-input v-model="model.examId" placeholder="请输入考试id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="试卷id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paperId">
              <a-input v-model="model.paperId" placeholder="请输入试卷id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="考试名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="examName">
              <a-input v-model="model.examName" placeholder="请输入考试名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="试卷名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paperName">
              <a-input v-model="model.paperName" placeholder="请输入试卷名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="试卷类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paperType">
              <a-input-number v-model="model.paperType" placeholder="请输入试卷类型" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="科目id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="subjectId">
              <a-input-number v-model="model.subjectId" placeholder="请输入科目id" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="系统得分" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="systemScore">
              <a-input-number v-model="model.systemScore" placeholder="请输入系统得分" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最终得分" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userScore">
              <a-input-number v-model="model.userScore" placeholder="请输入最终得分" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="试卷总分" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paperScore">
              <a-input-number v-model="model.paperScore" placeholder="请输入试卷总分" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="做对数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="questionCorrect">
              <a-input-number v-model="model.questionCorrect" placeholder="请输入做对数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="题目总数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="questionCount">
              <a-input-number v-model="model.questionCount" placeholder="请输入题目总数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所花时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="doTime">
              <a-input-number v-model="model.doTime" placeholder="请输入所花时间" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态（已批改，未批改）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <a-input-number v-model="model.status" placeholder="请输入状态（已批改，未批改）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="答题人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createUser">
              <a-input-number v-model="model.createUser" placeholder="请输入答题人" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="任务id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskExamId">
              <a-input-number v-model="model.taskExamId" placeholder="请输入任务id" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'OesExamPaperAnswerForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/exampaperanswer/oesExamPaperAnswer/add",
          edit: "/exampaperanswer/oesExamPaperAnswer/edit",
          queryById: "/exampaperanswer/oesExamPaperAnswer/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>